package com.laiketui.order.controller;

import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.order.api.params.wechatPay.PaymentParams;
import com.laiketui.order.service.wechatPay.WechatPayService;
import com.laiketui.root.annotation.HttpApiMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/v2/wechatPay")
public class WeChatPayOrderController {

    @Autowired
    private WechatPayService wechatPayService;

    @PostMapping("/pay")
    public Map<String, String> pay(@RequestBody PaymentParams params) {
        return wechatPayService.pay(params);
    }

    @PostMapping("/weChatNotifyV2")
    @HttpApiMethod(urlMapping = {"app.orderV2.weChatNotify"})
    public Result weChatNotifyV2(HttpServletRequest request){
        try {
            return Result.success(wechatPayService.weChatNotifyV2(request));
//            return Result.success(weChatPayOrderFeign.weChatNotifyV2(request));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage(), e.getMethod());
        }
    }


}
